from marshmallow import Schema, fields, ValidationError, validate, validates, pre_load, validates_schema
from base.schema import BaseSchema


class GetMobielCoseSchema(BaseSchema):
    mobile = fields.String(label='手机号', required=True, error_messages={"required": "请输入手机号。"})


class MobielLoginSchema(BaseSchema):
    mobile = fields.String(label='手机号', required=True, error_messages={"required": "请输入手机号。"})
    code = fields.String(label='验证码', required=True, error_messages={"required": "请输入验证码。"})


class ChangeUserSchema(BaseSchema):
    username = fields.String(label='用户名', validate=validate.Length(min=3,max=32, error='昵称长度必须在3到32个字符。'))
    nick_name = fields.String(label='昵称', validate=validate.Length(min=3,max=32, error='昵称长度必须在3到32个字符。'))
    region = fields.String(label='区域')
    avatar_url = fields.String(label='头像地址')
    gender = fields.Integer(label='性别')
    birth_date = fields.Date(label='出生日期', format="%Y-%m-%d")


class UserUseGroupSchema(BaseSchema):
    group_type = fields.String()
    group_type_cn = fields.String()


class ReturnUserSchema(BaseSchema):
    id = fields.Int(dump_only=True)
    username = fields.String(label='用户名', dump_only=True)
    # password = fields.String(label='密码', dump_only=True)
    mobile = fields.String(label='手机号或电话', dump_only=True)
    email = fields.String(label='邮箱', dump_only=True)
    real_name = fields.String(label='真实姓名', dump_only=True)
    nick_name = fields.String(label='昵称', dump_only=True)
    region = fields.String(label='区域', dump_only=True)
    # avatar_url = fields.String(label='头像地址', dump_only=True)
    avatar_url = fields.String(label='头像地址', dump_only=True)
    gender = fields.Integer(label='性别', dump_only=True)
    birth_date = fields.Date(label='出生日期', format="%Y-%m-%d", dump_only=True)
    # group_id = fields.Integer(label='用户组', dump_only=True)
    group = fields.Nested(UserUseGroupSchema(exclude=("update_time", "create_time")), dump_only=True)
    auth_id = fields.Integer(label='权限', dump_only=True)